package cn.edu.shou.lab.config.utils;

import org.springframework.cglib.beans.BeanMap;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public final class FastUtils {
    public static String frontEndLog(String log) {
        return "<<" + log + ">>";
    }

    public static String hightLightLog(String log) {
        return "\033[31;4m" + log + "\033[0m";
    }

    public static int stdInteger(Integer i) {
        return null != i ? i : 0;
    }

    public static List<String> getOneColnumOfList(List<?> list, String field){
        List<String> result = new ArrayList<>();
        for(Object o : list){
            Map<String, Object> map = BeanMap.create(o);
            result.add(map.get(field).toString());
        }
        return result;
    }

    public static String getCurrentDateTimeString(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }

    public static boolean emptyStringCheck(String... args){
        if(args == null || args.length == 0){
            throw new RuntimeException("args can not be null");
        }
        for(String arg : args){
            if(arg == null || arg.isEmpty()) {
                throw new RuntimeException("some args can not be null");
            }
        }
        return true;
    }

}
